<template>
  <div>
<van-cell title="搜索历史">
    <div v-if="isDeleteShow">
            <!-- 方式2.通过数组方法删除所有 -->
            <!-- <span @click="searchHistories.splice(0)">全部删除</span> -->
      <span @click="$emit('delete-search-histories')">全部删除</span>
      &nbsp;&nbsp;
    <span @click="isDeleteShow = false">完成</span>
    </div>
<van-icon v-else name="delete-o" @click="isDeleteShow = true"/>
</van-cell>
<van-cell :title="item" v-for="(item, index) in searchHistories" :key="index" @click="onItemCLICK(item,index)">
  <van-icon name="close" v-show="isDeleteShow"/>
   </van-cell>
  </div>
</template>

<script>
export default {
  name: 'hisytory',
  props: {
    searchHistories: {
      type: Array,
      require: true
    }
  },
  components: {},
  data () {
    return {
      isDeleteShow: false
    }
  },
  created () {

  },
  methods: {
    onItemCLICK (item, index) {
      if (this.isDeleteShow) {
        // 删除
        this.searchHistories.splice(index, 1)
      } else {
        this.$emit('search', item)
      }
    }
  }
}
</script>

<style lang="less" scoped>

</style>
